import { Description, Feature, Glyph, Interesting } from '$lib/components';
import { registerLocationTrigger } from '$lib/pos2';
import { Types, defineComponent } from '$lib/ecs';
import { addFlashBlind } from './flashblind';
import { log } from '$lib/log';
import { describe } from '$lib';

const FlashBlindTrap = defineComponent('FlashBlindTrap', {
  delay: Types.ui16,
});

export const flashBlindTrap = [
  [Feature],
  [Interesting],
  [FlashBlindTrap, {
    delay: 20,
  }],
  [Description, {
    summary: 'blinding flash trap',
  }],
  [Glyph, {
    glyph: '^',
  }],
];

registerLocationTrigger(FlashBlindTrap, (world, trap, e) => {
  const delay = FlashBlindTrap.delay[trap];
  log(`${describe(world, e)} is blinded by a bright flash of light for ${delay}!`);
  addFlashBlind(world, e, delay);
});
